home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 8 / Revista CD Expert nº 08 CD1.iso / Utilitarios / Programacao / Pacific C for DOS / EXAMPLES / CHK.C < prev    next >
C/C++ Source or Header  |  1995-03-08  |  819b  |  32 lines

  1. #include    <stdio.h>
  2.  
  3. /*
  4.  *    CHK.C    32 bit checksum generator.  Generates
  5.  *    and prints checksums for all files specified
  6.  *    on the command line.
  7.  *
  8.  *    Usage: CHK [files]
  9.  *
  10.  *    Compile with PACC -R or "_getargs() wildcard expansion"
  11.  *    if you want it to handle wildcards, e.g. CHK *.EXE
  12.  */
  13.  
  14. unsigned long    chk;        /* checksum accumulator */
  15. unsigned char    c;        /* character read from file */
  16. FILE *        infile;        /* input file handle */
  17.  
  18. main(int argc, char ** argv)
  19. {
  20.     while(--argc) {        /* while there are more arguments */
  21.         ++argv;        /* point at next file argument */
  22.         if (infile = fopen(argv[0], "rb")) {
  23.             chk = 0;
  24.             while (fread(&c, sizeof(c), 1, infile))
  25.                 chk += c;
  26.             fclose(infile);
  27.             printf("%s: %8.8lX\n", argv[0], chk);
  28.         } else
  29.             fprintf(stderr, "Cannot open %s\n", argv[0]);
  30.     }
  31. }
  32.